using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace JlPay.Sdk.Models.Openmerch.Device
{
    /// <summary>
    /// 设备信息
    /// @author liaochangyi
    /// @since 2025-01-25
    /// </summary>
    public class DeviceInfo
    {
        /// <summary>
        /// 设备硬件序列号（SN）
        /// </summary>
        [JsonPropertyName("device_no")]
        public string? DeviceNo { get; set; }

        /// <summary>
        /// 终端编号
        /// </summary>
        [JsonPropertyName("term_no")]
        public string? TermNo { get; set; }

        /// <summary>
        /// 商户号
        /// </summary>
        [JsonPropertyName("merch_no")]
        public string? MerchNo { get; set; }

        /// <summary>
        /// 状态：0-待启用 1-启用 2-停用 3-注销
        /// </summary>
        [JsonPropertyName("status")]
        public string? Status { get; set; }

        /// <summary>
        /// 设备型号
        /// </summary>
        [JsonPropertyName("model")]
        public string? Model { get; set; }

        /// <summary>
        /// 设备类型：02-传统POS 04-智能POS 05-智能POS AD-音响 CD-收银台 EP-电子码牌 PT-打印机 QR-码付设备 SP-立牌
        /// </summary>
        [JsonPropertyName("device_type")]
        public string? DeviceType { get; set; }

        /// <summary>
        /// 供应商
        /// </summary>
        [JsonPropertyName("supplier")]
        public string? Supplier { get; set; }

        /// <summary>
        /// 商户名称
        /// </summary>
        [JsonPropertyName("merch_name")]
        public string? MerchName { get; set; }

        /// <summary>
        /// 打印商户名称，签购单上的商户名称
        /// </summary>
        [JsonPropertyName("print_merch_name")]
        public string? PrintMerchName { get; set; }

        /// <summary>
        /// 地址
        /// </summary>
        [JsonPropertyName("address")]
        public string? Address { get; set; }

        /// <summary>
        /// 加机时间，yyyy-mm-dd HH:mm:ss
        /// </summary>
        [JsonPropertyName("install_time")]
        public string? InstallTime { get; set; }

        /// <summary>
        /// 更新时间，yyyy-mm-dd HH:mm:ss
        /// </summary>
        [JsonPropertyName("update_time")]
        public string? UpdateTime { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public DeviceInfo()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="deviceDict">设备信息字典</param>
        public DeviceInfo(Dictionary<string, object>? deviceDict)
        {
            if (deviceDict != null)
            {
                DeviceNo = deviceDict.TryGetValue("device_no", out var deviceNo) ? deviceNo?.ToString() : null;
                TermNo = deviceDict.TryGetValue("term_no", out var termNo) ? termNo?.ToString() : null;
                MerchNo = deviceDict.TryGetValue("merch_no", out var merchNo) ? merchNo?.ToString() : null;
                Status = deviceDict.TryGetValue("status", out var status) ? status?.ToString() : null;
                Model = deviceDict.TryGetValue("model", out var model) ? model?.ToString() : null;
                DeviceType = deviceDict.TryGetValue("device_type", out var deviceType) ? deviceType?.ToString() : null;
                Supplier = deviceDict.TryGetValue("supplier", out var supplier) ? supplier?.ToString() : null;
                MerchName = deviceDict.TryGetValue("merch_name", out var merchName) ? merchName?.ToString() : null;
                PrintMerchName = deviceDict.TryGetValue("print_merch_name", out var printMerchName) ? printMerchName?.ToString() : null;
                Address = deviceDict.TryGetValue("address", out var address) ? address?.ToString() : null;
                InstallTime = deviceDict.TryGetValue("install_time", out var installTime) ? installTime?.ToString() : null;
                UpdateTime = deviceDict.TryGetValue("update_time", out var updateTime) ? updateTime?.ToString() : null;
            }
        }

        /// <summary>
        /// 转换为字典格式
        /// </summary>
        /// <returns>字典数据</returns>
        public Dictionary<string, object?> ToDictionary()
        {
            return new Dictionary<string, object?>
            {
                ["device_no"] = DeviceNo,
                ["term_no"] = TermNo,
                ["merch_no"] = MerchNo,
                ["status"] = Status,
                ["model"] = Model,
                ["device_type"] = DeviceType,
                ["supplier"] = Supplier,
                ["merch_name"] = MerchName,
                ["print_merch_name"] = PrintMerchName,
                ["address"] = Address,
                ["install_time"] = InstallTime,
                ["update_time"] = UpdateTime
            };
        }
    }
} 